# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models

# Create your models here.
class UserModel(models.Model):
    openid = models.CharField(max_length=20)
    nickname = models.CharField(max_length=20)
    
    @classmethod
    def vsave(cls,openids):
        UserModel.objects.all().delete()
        for openid in openids:
            UserModel(openid=openid,nickname="").save()
    @classmethod
    def vupdate(cls,openid,nickname):
        UserModel.objects.filter(openid=openid).update(nickname=nickname)
    
    @classmethod
    def user(cls,openid):
        UserModel.objects.get(openid=openid)
class SettingsModel(models.Model):
    key = models.CharField(max_length=20)
    value = models.CharField(max_length=20)
    @classmethod
    def vset(cls,key,value):
        content = ""
        obj = SettingsModel.objects.filter(key=key)
        if obj:
            obj.update(value=value)
        else:
            SettingsModel(key=key,value=value).save()
        content = "saved"
        return True
    @classmethod
    def vget(cls,key):
        return SettingsModel.objects.get(key=key).value